package org.alex.netShop.pages;


import org.alex.netShop.interfaces.Customer;
import org.alex.netShop.interfaces.Customers;
import org.alex.netShop.interfaces.User;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
import org.apache.tapestry5.ioc.annotations.Inject;

public class ViewCustomer
{
	@Inject
	@Property
	private Customers customers;
	
	@InjectPage
	private CustomerDetails customerDetailsPage;
	@InjectPage
	private AddPurchase addPurchase;

	@Persist
	@Property
	private Customer customer;
	

	
	@OnEvent(component = "customerDetailsLink")
	Object onShowDetails(String name) {
		Customer customer = customers.retrieveCustomer(name);
		customerDetailsPage.setChosenCustomer(customer);
		
		return customerDetailsPage;
	}
	@OnEvent(component = "addCustomerLink")
	Object onCustomerLink(String name) {

		addPurchase.setPurchaseCustomer(name);
		return addPurchase;
	}
	@SessionState
	private User user;

	private boolean userExists;
	
	public User getUser() {
		return user;
	}
	
	Object onActivate() {
		if (!userExists) return Login.class;
		return null;
	}

}
